@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.invitingAdvertList')}}">招商广告</a>
        </div>
        @include("admin.common.inviting-advert-header")
        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.invitingAdvertSet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>图片</th>
                    <th>地址</th>
                    <th>联系电话</th>
                    <th>招商类别</th>
                    <th>描述</th>
                    <th>创建时间</th>
                    <th>板块划分</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($adverts) > 0)
                    @foreach($adverts as $advert)
                        <tr id="advert_{{$advert->id}}">
                            <td>{{$advert->id}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($advert->img_id !== 0)
                                        <a href="javascript:void(0);" class="openimg" data-key="{{$advert->img_id}}"><img src="{{$advert->photo_url}}" alt="{{$advert->photo_url}}"></a>
                                    @else
                                        <img src="{{url('images/default-img.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td>{{$advert->province}}{{$advert->city}}{{$advert->area}}{{$advert->address_detail}}</td>
                            <td>{{$advert->phone}}</td>
                            <td>{{$advert->classify}}</td>
                            <td>{{$advert->desc}}</td>
                            <td>{{$advert->created_at}}</td>
                            <td>{{$advert->bankuai}}</td>
                            <td><a class="setstatus" id="status_{{$advert->id}}" href="javascript:void(0);" data-id="{{$advert->id}}">@if($advert->status == 0)<span class="color2">待审核</span> @else <span class="color4">通过审核</span> @endif</a></td>
                            <td><a class="color2" href="{{route("Admin.Home.invitingAdvertSet")}}?id={{$advert->id}}">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$advert->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $adverts->render();?>
        </div>
    </div>
    <script>
        $(function () {
            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '可能会影响招商信息表格，你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.sys.delInvitingAdvert')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#advert_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });

            $(document).on('click','.setstatus',function(){
                var id = $(this).data("id");

                $.ajax({
                    url:'{{route('Api.Admin.sys.checkAdvent')}}',
                    type:'post',
                    dataType:'json',
                    data:{id:id},
                    success:function(obj){
                        if(obj.level == "success"){
                            noty({text:obj.message,type:obj.level,timeout:600,
                                callback:{
                                    afterClose:function(){
                                        window.location.reload();
                                    }
                                }
                            });
                        }else{
                            noty({type:obj.level,text:obj.message,timeout:600});
                        }
                    },
                    error:function(obj){
                        console.log(obj);
                    }

                });
            });
        })



    </script>
@endsection
